﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using SharedLib.XmlDataModel;
using System.Xml;
using SharedLib.Helpers;
using System.IO;
namespace Tracy.DataModel
{
    public class FanSubGroup : XmlDataModelWithAliases, IComparable
    {
        public FanSubGroup() : base() { }
        public FanSubGroup(XmlNode node):base(node){
        }

        /// <summary>
        /// Name of the Fan sub group
        /// </summary>
        public override string Name
        {
            get { return Attributes["name"]; }
            set { Attributes["name"] = value; }
        }

        public override int GetHashCode()
        {
            if (Name != null)
                return Name.GetHashCode();
            else
                return "".GetHashCode();
        }

        public override bool Equals(object obj)
        {
            if (obj is FanSubGroup)
            {
                return Name == ((FanSubGroup)obj).Name;
            }
            return base.Equals(obj);
        }

        public override string RootNodeName
        {
            get
            {
                return "fan-sub-group";
            }
        }

        public override string ToString()
        {
            return Name;
        }

        public int CompareTo(object obj)
        {
            if (obj != null)
            {
                return this.ToString().CompareTo(obj.ToString());
            }

            return 1;
        }

        public static string GetCombinationName(ICollection<FanSubGroup> fanSubGroups)
        {
            StringWriter swFanSubGroups = new StringWriter();
            bool isFirstFanSubGroup = true;
            foreach (FanSubGroup g in fanSubGroups)
            {
                if (isFirstFanSubGroup)
                {
                    isFirstFanSubGroup = false;
                }
                else
                {
                    swFanSubGroups.Write("&");
                }
                swFanSubGroups.Write(g.Name);
            }
            return swFanSubGroups.ToString();
        }
    }
}
